@extends('admin.main')
@section('content')
    <div class="daohang">
        <ul>
            <li>
                <button type="button" class="am-btn am-btn-default am-radius am-btn-xs"> 优惠券管理</button>
            </li>
        </ul>
    </div>
    <div class="admin-biaogelist">

        <div class="listbiaoti am-cf">
            <ul class="am-icon-flag on"> 优惠券列表</ul>
            <dl>
                @if(isset($_GET['type']) && $_GET['type'] == 1)
                    <button type="button" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus"
                            onclick="window.location.href='{{urlAdmin('favorable','getAddFavorablezk')}}?type=1'"> 新增折扣券
                    </button>
                @endif
                @if(isset($_GET['type']) && $_GET['type'] == 2)
                    <button type="button" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus"
                            onclick="window.location.href='{{urlAdmin('favorable','getAddFavorablezk')}}?type=2'"> 新增代金券
                    </button>
                @endif
                @if(isset($_GET['type']) && $_GET['type'] == 3)
                    <button type="button" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus"
                            onclick="window.location.href='{{urlAdmin('favorable','getAddFavorablezk')}}?type=3'"> 新增体验券
                    </button>
                @endif
            </dl>

        </div>

        <div class="am-tabs am-margin" data-am-tabs>
            <ul class="am-tabs-nav am-nav am-nav-tabs">
                <li @if(isset($_GET['type']) && $_GET['type'] == 1)class="am-active"
                    @endif onclick="javascript:window.location.href='{{urlAdmin('favorable','getIndex',['type'=>1])}}'">
                    <a href="">折扣券</a></li>
                <li @if(isset($_GET['type']) && $_GET['type'] == 2)class="am-active"
                    @endif onclick="javascript:window.location.href='{{urlAdmin('favorable','getIndex',['type'=>2])}}'">
                    <a href="">代金券</a></li>
                <li @if(isset($_GET['type']) && $_GET['type'] == 3)class="am-active"
                    @endif onclick="javascript:window.location.href='{{urlAdmin('favorable','getIndex',['type'=>3])}}'">
                    <a href="">体验券</a></li>
            </ul>
            <div class="am-tabs-bd">
                <form class="am-form am-g">
                    <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped">
                        <thead>
                        <tr class="am-success">
                            <th class="table-id">ID</th>
                            <th class="table-title">优惠券名称</th>
                            <th class="table-type">序列号</th>
                            <th class="table-author">使用条件</th>
                            <th class="table-author">抵扣金额</th>
                            <th class="table-date am-hide-sm-only">折扣</th>
                            <th class="table-author">余量</th>
                            <th class="table-author">有效期</th>
                            <th width="163px" class="table-set">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @if(!empty($res['data']))
                            @foreach($res['data'] as $v)
                                <tr>
                                    <td>{{$v['id']}}</td>
                                    <td>{{$v['title']}}</td>
                                    <td>{{$v['id_no']}}</td>
                                    <td class="am-hide-sm-only">{{$v['consume_money']}}</td>
                                    <td>{{$v['cash']}}</td>
                                    <td>{{$v['discount']}}</td>
                                    <td>{{$v['rest_num']}}/{{$v['num']}}</td>
                                    <td class="am-hide-sm-only">{{$v['created_at']}}</td>
                                    <td width="20%">@if($v['type']==1)<a
                                                href="{{urlAdmin("favorable",'getAddFavorablezk')}}?id={{$v['id']}}&type={{$v['type']}}"
                                                class="abtn">编辑</a>@else<a
                                                href="{{urlAdmin("favorable",'getAddFavorabledj')}}?id={{$v['id']}}&type={{$v['type']}}"
                                                class="abtn">编辑</a> @endif<a href="javascript:void(0)" onclick="del({{$v['id']}})"
                                                                             class="abtn ff6600">删除</a><a
                                                href="/center/favorable/duihuan-list?f_id={{$v['id']}}"
                                                class="abtn blue">兑换记录</a></td>
                                </tr>
                            @endforeach
                        @else
                            <tr>
                                <td colspan="8" style="text-align: center"><span>暂无数据~</span></td>

                            </tr>
                        @endif
                        </tbody>
                    </table>
                    @if(!empty($res['pageNoList']))
                        <ul class="am-pagination am-fr">
                            <li class="am-disabled"><a href="#">«</a></li>
                            @foreach($res['pageNoList'] as $v)
                                @if($res['current_page']==$v)
                                    <li class="am-active"><a
                                                href="{{urlAdmin('favorable','getIndex')}}?page={{$v}}@if(isset($_GET['type']))&type={{$_GET['type']}}@endif">{{$v}}</a>
                                    </li>
                                @else
                                    <li>
                                        <a href="{{urlAdmin('favorable','getIndex')}}?page={{$v}}@if(isset($_GET['type']))&type={{$_GET['type']}}@endif">{{$v}}</a>
                                    </li>
                                @endif
                            @endforeach
                            <li><a href="#">»</a></li>
                        </ul>
                    @endif
                    @include('admin.footer')
                    @section('css')
                        <link type="text/css" src="/assets/layer/skin/default/layer.css"/>
                    @endsection
                    @section('js')
                        <script type="text/javascript" src="/assets/layer/layer.js"></script>
                    @endsection
                    @section('script')
                        <script>
                            function del(id) {
                                layer.confirm('您确定要删除吗？', {
                                    btn: ['确定', '取消'] //按钮
                                }, function () {
                                    $.ajax({
                                        type: "get",
                                        url: "{{urlAdmin('favorable','getDelFavorable')}}?id=" + id,
                                        dataType: "json",
                                        success: function (res) {
                                            if (res['state'] == 1) {
                                                layer.msg('删除成功', {icon: 6});
                                            } else {
                                                layer.msg('删除失败', {icon: 5});
                                            }
                                        }
                                    })

                                });
                            }
                        </script>
                    @endsection
                </form>
            </div>
        </div>
    </div>
    </div>
@endsection